package com.contractpage.ec;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.contractpage.ec.entity.Appoint;
import com.contractpage.ec.entity.PrinterDepartment;
import com.contractpage.ec.service.AppointService;
import com.contractpage.ec.service.PrinterDepartmentService;
import com.richgo.thrsys.entity.contract.TSaleProject;
import com.richgo.thrsys.service.contract.TElectronicContractService;
import com.user.entity.org.DeptTree;
import com.user.service.org.OrgService;

@Controller
public class Hengtian {
	@Autowired
	private HttpServletRequest request;
	@Autowired
	private HttpServletResponse response;
	@Autowired
	private TElectronicContractService tElectronicContractService;
	@Autowired
	private PrinterDepartmentService printerDepartmentService;
	@Autowired
	private AppointService	appointService;
	
	/*@Autowired
	private ICustomerService iCustomerService;*/
	
	@Autowired
	private OrgService orgService;//.selectAllDeptTree()
	
	
	@RequestMapping(value = "org/findList")
	@ResponseBody
	public Object findList(){
		return printerDepartmentService.findAllList(new PrinterDepartment());
	}
	
	@RequestMapping(value = "appoint/findProjects")
	@ResponseBody
	public Object findProjects(){
		return appointService.findAllListGroupProject(new Appoint());
	}
	
	@RequestMapping(value = "org/selectAllDeptTree")
	@ResponseBody
	public Object selectAllDeptTree(){
		List<DeptTree> trees = orgService.selectAllDeptTree();
		List<DeptTree> list = new ArrayList<DeptTree>();
		transferSourceTree(trees, list);
		return list;
	}

	public void transferSourceTree(List<DeptTree> trees,List<DeptTree> list){
		for(DeptTree dept : trees){
			System.out.println(dept.toString());
			list.add(dept);
			List<DeptTree> t = dept.getChildrenList();
			transferSourceTree(t,list);
		}
	}
	
	@RequestMapping(value = "project/find")
	@ResponseBody
	public Object findProject(String projectName,String projectShotname){
		Map<String,Object> map = tElectronicContractService.selectSomeProjectsByFileds(1, 10000000, projectName, projectShotname, "");
		List<TSaleProject> list = (List<TSaleProject>)map.get("list");
		return list;
	}
	
	/*@RequestMapping(value = "appointment/getInfoByReserveNo")
	@ResponseBody
	public Object getInfoByReserveNo(String reserveNo){
		CustomerAppointmentInfoVO appointment = iCustomerService.getAppointmentInfo(reserveNo);
		return appointment;
	}*/
	
	/*@RequestMapping(value = "appointment/getInfoByProjectName")
	@ResponseBody
	public Object getInfoByProjectName(String projectName){
		return thrsysReserveService.getReserveMsgByProjectNo(projectName);
	}*/
	
	@RequestMapping(value = "appointment/list")
	@ResponseBody
	public Object list(){
		return null;
	}
	
}
